import * as vscode from "vscode";
import { HarmonyPilotGUIWebviewViewProvider } from "../HarmonyPilotGUIWebviewViewProvider";
import { registerAllCommands } from "../commands";
import { VerticalDiffCodeLensProvider } from '../diff/vertical/VerticalPerLineCodeLensProvider';
import { VerticalDiffManager } from "../diff/vertical/manager";
import { LLMFactory } from "../../core/llm/llmFactory";

const { registerCodeLensProvider } = vscode.languages;

export class VsCodeExtension {

    private verticalDiffManager: VerticalDiffManager;

    private sidebar: HarmonyPilotGUIWebviewViewProvider;

    constructor(context: vscode.ExtensionContext) {
        this.verticalDiffManager = new VerticalDiffManager();
        let provider = new VerticalDiffCodeLensProvider(
            this.verticalDiffManager.fileUriToCodeLens,
        );
        registerCodeLensProvider(
            "*",
            provider,
        );
        this.verticalDiffManager.refreshCodeLens = provider.refresh.bind(provider);
        
        // 获取模型工厂
        const llmFactory = new LLMFactory();

        // 创建webview
        this.sidebar = new HarmonyPilotGUIWebviewViewProvider(context.extensionUri);

        // 注册所有命令
        registerAllCommands(context, this.verticalDiffManager, llmFactory, this.sidebar);

        // 注册侧边栏
        context.subscriptions.push(
            vscode.window.registerWebviewViewProvider(
            "HarmonyPilot.harmonyPilotGUIView",
            this.sidebar,
            {
                webviewOptions: { retainContextWhenHidden: true },
            },
            ),
        );
    
    }   
}